/**
 * Copyright (c) 2009 blurredVision
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
 * associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT 
 * OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */
#ifndef __GUI_LIST_H__
#define __GUI_LIST_H__

#pragma once

#include "Component.h"
#include "IHighlightable.h"
#include "ISelectable.h"
#include "IChangeListener.h"
#include <string>
#include <vector>

namespace gui {

/**
 * \ingroup coreGUI
 *
 * The GUI List class.<br>
 * A list of strings displayed as a GUI elements.
 *
 * \date 03-28-2007
 *
 * \author juckel
 * \author altjohann
 * 
 */
class GUI_EXPORT List 
 :	public Component, 
	public IHighlightable,
	public ISelectable, 
	public IChangeObserver
{
public:
	/// Create a new list
	List(void);
	virtual ~List(void);

	/// Add a string to the list
	void addString(const std::string&);

	/// Remove a string from the list
	void removeString(const std::string&);

	/// Remove the selected element from the list
	bool removeSelected();

	/// Clear the list
	virtual void clear();

	/// Set the dimension of the gui element
	void setDimension(int x, int y, int w, int h);
	
	virtual bool processMouse(int _x, int _y, int _z, int _button);

	/// Set the selected item to the specified string 
	void setSelectedItem(const std::string &item);
	
	/// Set how many entries are visible at the same time
	void setNumberOfVisibleEntries(int iNumbOfEntries);
	
	/// Set the steps to scroll up or down
	void setScrollSteps(int _steps);
	
	/// Return the number of items
	int getNumItems() const;

	/// Get the string of the selected item
	std::string getSelectedItem() const;

	/// Constrain the width to a certain size. Adding a string will not alter the width of the list
	void constrainWidth(bool val);

	/// Set button for scrolling the list up
	void setButtonUp( ITexture *texture);
	
	/// Set button for scrolling the list down
	void setButtonDown( ITexture *texture);

	/// Draw the GUI element
	virtual void draw();

	/// Draw the highlighted row of the list
	virtual void drawHighlight();

	/// Return the type of the GUI element
	virtual inline const int getGUIType() const { return GUI_LIST; }

	int getMarkedItem();
	void setMarkedItem(int index);

protected:
	void updateDimension();

	/// Mouse event functions
	virtual void onMouseEntered(const MouseEvent &me);
	virtual void onMouseLeft(const MouseEvent &me);
	virtual void onMouseReleased(const MouseEvent &me);

	void processMouseWheel(int z);

	int iVisibleEntries;		///< The number of visible entries. If -1, the list is not limited in length
	int iNumbOfEntries;			///< The total number of entries
	int iStartElement;			///< The start element if the list is limited in visible items
	int iScrollSteps;			///< The number of elements to scroll per mouse click
	bool bConstrainWidth;		///< The width the list is constrained to

	int m_lastZ;				///< Last value of z
	
	gui_list strings;			///< Storage for the list elements

	ITexture *pButtonUp;
	ITexture *pButtonDown;

	int m_iMarkedItem;
	math::Vector4 m_vMarkedColor;
};

} // namespace

#endif
